{template 'common/header'} 
{template 'web/common'} 

<style type='text/css'>
	
</style>

<div class="main">

	<ul class="nav nav-tabs">
	    <li {if $operation=='display'}class="active"{/if}><a href="{php echo $this->createWebUrl('category',array('op'=>'display'))}">海报分类</a></li>
	    <li {if $operation=='post'}class="active"{/if}><a href="{php echo $this->createWebUrl('category',array('op'=>'post','id'=>$_GPC['id']))}">添加分类</a></li>
	</ul>

	{if $operation == 'display'}
		<div class="category">
	        <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" >
				<div class="alert alert-warning alert-dismissable">
				  	 温馨提示：海报分类（后端便于管理，前端便于生成属于自己想要的海报）
				</div>
				<div class="panel panel-default">
					<div class="panel-heading">海报分类</div>
					<div class="panel-body table-responsive">
						<div class="dd" id="div_nestable">
							<ol class="dd-list" style="margin-top: 20px;">
								{loop $category $row}
									{if $row['parentid'] == 0}
										<li class="dd-item" data-id="{$row['id']}">
		                                    <div class="dd-handle"  style='width:100%;'>
		                                    	<img src="{php echo tomedia($row['thumb'])}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' /> &nbsp;
		                                        [ID: {$row['id']}] {$row['name']} 
		                                        <span class="pull-right">
		                                            <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('category', array('parentid' => $row['id'], 'op' => 'post'))}" title='添加子分类' ><i class="fa fa-plus"></i></a>
	                                             	<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('category', array('id' => $row['id'], 'op' => 'post'))}" title="修改" ><i class="fa fa-edit"></i></a>
		                                            <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('category', array('id' => $row['id'], 'op' => 'delete'))}" title='删除' onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i></a>
		                                        </span>
		                                    </div>
		                                    {if count($children[$row['id']]) > 0}
												<ol class="dd-list" style='width: 100%;'>
													{loop $children[$row['id']] $child}
														<li class="dd-item" data-id="{$child['id']}">
				                                            <div class="dd-handle">
				                                                <img src="{php echo tomedia($child['thumb'])}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' /> &nbsp;
				                                                [ID: {$child['id']}] {$child['name']}
				                                                <span class="pull-right">
				                                                     <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('category', array('id' => $child['id'], 'op' => 'post'))}" title="修改" ><i class="fa fa-edit"></i></a>
				                                                     <a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('category', array('id' => $child['id'], 'op' => 'delete'))}" title='删除' onclick="return confirm('确认删除此分类吗？');return false;"><i class="fa fa-remove"></i></a>
				                                                </span>
				                                            </div>
														</li>
													{/loop}
												</ol>
											{/if}
										</li>
									{/if}
								{/loop}
							</ol>
							<table class='table'>
                                <tr>
	                                <td>
	                                    <a href="{php echo $this->createWebUrl('category',array('op'=>'post'))}" class="btn btn-default"><i class="fa fa-plus"></i> 添加新分类</a>
	                                    <input id="save_category" type="button" class="btn btn-primary" value="保存分类修改">
	                                    <input id="nestableMenu" type="button" class="btn btn-info" value="全部合并">
	                                    <input type="hidden" name="datas" value="" />
	                                </td>
	                            </tr>
	                   		</table>
						</div>
					</div>
				</div>
			</form>
	    </div>
	</div>
	{elseif $operation == 'post'}
		<div class="main">
		    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
		    	<input type="hidden" name="parentid" value="{$_GPC['parentid']}" />
		    	<input type="hidden" name="id" value="{$_GPC['id']}" />
		    	<input type="hidden" name="op" value="{$_GPC['op']}" />
		    	
		        <div class="panel panel-default">
		            <div class="panel-heading">
	                	商品分类
		            </div>
		            <div class="panel-body">
		            	<div class="form-group">
		                	<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类连接(点击复制)</label>
			                <div class="col-sm-9 col-xs-12">
			                    <p class="form-control-static">
			                    	<a href="javascript:;" title="点击复制连接" id="cp">                                  		
			                    		{if empty($parent)}
			                           		{php echo $_W['siteroot'].ltrim($this->createMobileUrl('list',array('pcate'=>$item['id'])),"./")}
			                           	{else}
			                                {php echo $_W['siteroot'].ltrim($this->createMobileUrl('list',array('ccate'=>$item['id'])),"./")}
			                           	{/if}
			                    	</a>
			                    </p>
			                </div>
		            	</div>
		            	
		                {if !empty($parent)}
			                <div class="form-group">
			                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>
			                    <div class="col-sm-9 col-xs-12 control-label" style="text-align:left;">
			                        {$parent['name']}
			                    </div>
			                </div>
		                {/if}
		                
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
		                    <div class="col-sm-9 col-xs-12">
		                    	<input type="text" name="displayorder" class="form-control" value="{$item['displayorder']}">
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">
		                    	<span style="color:red">*</span>分类名称
		                    </label>
		                    <div class="col-sm-9 col-xs-12">
		                    	<input type="text" name="catename" class="form-control" value="{$item['name']}">
		                    </div>
		                </div>
		                
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类图片</label>
		                    <div class="col-sm-9 col-xs-12">
		                    	<input type="hidden" name="thumb_old" value="{$item['thumb']}" />
		                        {php echo tpl_form_field_image('thumb',$item['thumb'])}
		                        <span class="help-block">建议尺寸: 100*100，或正方型图片 </span>
		                    </div>
			            </div>
			            
		                <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>
		                    <div class="col-sm-9 col-xs-12">
		                        <textarea name="description" class="form-control" cols="70">{$item['description']}</textarea>
		                    </div>
		                </div> 
		                
		              	<div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
		                    <div class="col-sm-9 col-xs-12">
                                <label class="radio-inline">
		                            <input type="radio" name="enabled" value="0" {if intval($item['enabled']) == 0}checked {/if}> 是
		                        </label>
		                        <label class="radio-inline">
		                            <input type="radio" name="enabled" value="1" {if intval($item['enabled']) == 1}checked{/if}> 否
		                        </label>
                            </div>
		                </div>
		                
                		<div class="form-group"></div>
                		
			            <div class="form-group">
		                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
		                    <div class="col-sm-9 col-xs-12">
	                           <input type="hidden" name="token" value="{$_W['token']}">
	                           <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" onclick="return formcheck()">
	                           <input type="button" name="back" onclick="history.back()" style="margin-left:10px;" value="返回列表" class="btn btn-default col-lg-1">
		                    </div>
			            </div>
		                
		            </div>
		        </div>
		      
		    </form>
		</div>
	{/if}
	
</div>

<script language="javascript" src="{php echo __STATIC__}/nestable/jquery.nestable.js"></script>
<link rel="stylesheet" type="text/css" href="{php echo __STATIC__}/nestable/nestable.css" />

<script language='javascript'>
    $(function(){
	    var depth = 2;
	    var str1=$('#div_nestable').nestable({maxDepth: depth });
	    $(".dd-handle a,dd-handle embed,dd-handle div").mousedown(function (e) {
            e.stopPropagation();
        }); 
	    
        var $expand = false;
        $('.dd').nestable('expandAll');
        $('#nestableMenu').on('click', function(e){
            if ($expand) {
                $expand = false;
                $('.dd').nestable('expandAll');
                $('#nestableMenu').val('全部合并');
            }else {
                $expand = true;
                $('.dd').nestable('collapseAll');
                $('#nestableMenu').val('全部展开');
            }
        });
        $("#save_category").click(function(){
    	 	var json = window.JSON.stringify($('#div_nestable').nestable("serialize"));
    	    $(':input[name=datas]').val(json);
    	    $('form').submit();
    	})
    	
    })
</script>

<script>
	require(['util'],function(u){
        $('#cp').each(function(){
    	   u.clip(this, $(this).text());
    	});
    });
    
    $('form').submit(function(){
        if($(':input[name=catename]').val()==''){
            Tip.focus(':input[name=catename]','请输入分类名称!');
            return false;
        }
        return true;
    });
</script>

{template 'common/footer'}